Find Content Items By Tag Caption

{ findItemsByTagName }

Returns a list of content items based on tag caption.

Method

/API2/content/findItemsByTagName

  • API Section: /API2/content
  • API Version: 2.0
  • From Release: 2020.0
  • Can be used by Non-admin accounts
  • Method operates via POST actions only.
  • Input Parameters

    Name

    tag

    Type

    string

    Description

    The tag caption to search

    Output Response

    Successful Result Code

    200

    Response List Type

    Description of Response Type

    A generic object used to contain ID's of items. Note that the response is returned as a list of items of this object type.

    Notes

    For this to be effective, content tags need to be set on items in the content system by users.

    Examples
    Find content items by tag (JavaScript):

    This example demonstrates how to find item's in the content manager using content tags. The results are then used to create dynamic embedding on a host page.

    The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.

    // URL of the Pyramid installation and the path to the API 2.0 REST methods
    var pyramidURL = "http://mysite.com/api2/";
    
    // step 1: authenticate admin account and get token
    // NOTE: callApi method is a generic REST method shown below.
    let token = callApi("auth/authenticateUser",{
    	"data":{
    		"userName":"adminUser",
    		"password":"abc123!"
    	}
    },false);
    log("got token "+ token );
    
    // step 2: get all content items in the content system that have been tagged with "embed"
    
    var tagName = "embed";
    
    let itemIds = callApi("content/findItemsByTagName", {
                "tag": tagName,
                "auth": token
            });
    
    
    // step 3: for each item in the search result list, embed it on the host page
    embedMultiple(itemIds.data);
    
    // ### embed function
        function embedMultiple(ids) {
            for (var i = 0; i < ids.length; i++) {
                var div = document.createElement("DIV");
                div.id = ids[i];
                div.style = "width: 1000px; height: 600px; border: 1ps solid blue;";
                document.getElementById("mainContainer").appendChild(div);
    
    	//use the Pyramid 'embed' method from the embed library 
    	//to add live content to each generated DIV elemt	
                pyramid.embed(div, {
                    id: ids[i],
                    host: "http://mysite.com",
                    contentType: "storyboard"
                });
            }
        }
    
    
    // ##### optional generic login method for debugging ##############
    function log(msg){
    	document.write(msg);
    	console.log(msg);
    }
    
    // ##### generic REST API calling method ##############
    function callApi(path,data,parseResult=true){
    	var xhttp = new XMLHttpRequest();
    	xhttp.open("POST", pyramidURL+path, false);
    	xhttp.send(JSON.stringify(data));
    	if(parseResult){
    		return JSON.parse(xhttp.responseText);
    	}else{
    		return xhttp.responseText;
    	}
    }